package com.yx.frame.jdbc;

import org.json.JSONArray;

/**
 * 
 * @author dw
 * @create_date 2019年11月12日
 */
public final class Table extends JSONArray {

	int columnIdx = 0;
	int countNum = 0;
	int pageNum = 0;
	
	String[] Str;
	
	String[] columnNames;

	protected Table(String[] columnNames) throws Exception {
		this.columnNames = columnNames;
	}
	protected Table(String[] columnNames,String[] str) throws Exception {
		this.columnNames = columnNames;
		this.Str = str;
	}
	protected Table(String[] columnNames,int countNum,int pageNum,String[] str) throws Exception {
		this.columnNames = columnNames;
		this.countNum = countNum;
		this.pageNum = pageNum;
		this.Str = str;
	}
	protected final void addRow(Row row) throws Exception {
		this.put(row);
	}
	
	public final Row getRow(int idx) throws Exception {
		return (Row) get(idx);
	}

	public final String getAt( int row,String columnName) throws Exception {
		return getRow(row).getAt(columnName);
	}

	public final String getAt(int row,int column) throws Exception {
		return getRow(row).getAt(columnNames[column]);
	}

	public final int getRowcount() {
		return this.length();
	}

	public final int getColumncount() {
		return getColumnNames().length;
	}

	public String[] getStrs() {
		return Str;
	}

	public String[] getColumnNames() {
		return columnNames;
	}
	public void copy(Table table) throws Exception {		
		int rowCount = table.getRowcount();
		for (int i = 0; i < rowCount; i++) {
			this.put(table.getRow(i));
		}
	}
	public final void unzip(int column) throws Exception {
		int rowCount = getRowcount();
		for (int i = 0; i < rowCount; i++) {
			getRow(i).unzip(columnNames[column]);
		}
	}
}
